package com.ok.community.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ok.common.domain.po.Result;
import com.ok.community.domain.po.OkBan;
import com.ok.community.service.IOkBanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 敏感词 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-29
 */
@Api(tags = "敏感词相关接口")
@RestController
@RequestMapping("/ban")
@RequiredArgsConstructor
public class OkBanController {

    private final IOkBanService okBanService;

    @ApiOperation(value = "增加敏感词")
    @PostMapping("/add")
    public Result add(String name){
        OkBan okBan = new OkBan();
        okBan.setName(name);
        okBanService.save(okBan);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "删除敏感词")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        okBanService.removeById(id);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "获取敏感词列表")
    @GetMapping("/page")
    public Result<Page<OkBan>> page(Integer pageNo,Integer pageSize){
        Page<OkBan> page = new Page<>(pageNo,pageSize);
        okBanService.page(page);
        LambdaQueryWrapper<OkBan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(OkBan::getUpdateTime);
        okBanService.page(page,queryWrapper);
        return Result.success(page);
    }
}
